
# Figure_6.R
# Aim: to reproduce Figure 6 of Atsusaka and Holbrook (2026)

library(tidyverse)
library(readxl)

# read the standardized data ---------------------------------------------------
ours <- read_csv("archive-election.csv") %>%
  select(state, year) %>%
  mutate(data = "Archive")


# read the reference dataset ------------------------------------------------------
referece_data <- read_csv("cvr_files_summary.csv") %>%
  filter(year >= 2004 & year <= 2024) %>%
  select(state, year) %>%
  mutate(data = "Reference dataset")


# Compare ----------------------------------------------------------------------

table(ours$state, useNA = "always")
table(referece_data$state, useNA = "always")

rbind(ours, referece_data) %>%
  count(state, data) %>%
  ggplot(aes(x = state, y = n, fill = data)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("darkcyan", alpha("gray70", 0.6))) +
  labs(x = "", y = "Number of observations", fill = "") +
  theme_bw() +
  theme(
    legend.position = "top",
    axis.text.x = element_text(hjust = 0.5)
  )

ggsave("Figure_6.pdf", width = 7, height = 3)
